/*
 * @lc app=leetcode.cn id=203 lang=java
 *
 * [203] 移除链表元素
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode removeElements(ListNode head, int val) {
        ListNode headtemp = new ListNode(0);
        headtemp.next = head;
        deleNode(headtemp, val);
        return headtemp.next;
    }
    public void deleNode(ListNode head,int val){
        if (head.next == null){
            return;
        }else if (head.next.val == val){
            ListNode temp = head.next;
            head.next = temp.next;
            if ( head.next.val == val){
                deleNode(head, val);
            }else
                deleNode(head.next, val);
        }else {
            deleNode(head.next, val);
        }
    }
}
// @lc code=end

